#pragma once
#include "QueryRetrieveSCU.h"
#include "CDbSetUI.h"
#include <comutil.h>



class CDbSearchUI : public WindowImplBase, public IListCallbackUI
{
public:
	CDbSearchUI(HWND hParent = NULL, HWND hOwner = NULL, BOOL bSelfDel = FALSE);
	~CDbSearchUI();

	void RefreshList();

public:
	LPCTSTR GetWindowClassName() const;

	virtual void OnFinalMessage(HWND hWnd);

	virtual void InitWindow();

	//virtual LRESULT ResponseDefaultKeyEvent(WPARAM wParam);

	virtual DString GetSkinFile();

	virtual DString GetSkinFolder();

	virtual CControlUI* CreateControl(LPCTSTR pstrClass);

	virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);

	virtual LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

	virtual LPCTSTR GetItemText(CControlUI* pControl, int iIndex, int iSubItem);

private:

	BOOL m_bSelfDel;
	HWND m_hOwner;
	DbConfig m_dbcfg;
	vector<FindItem> m_findList;
	vector<vector<string>> m_rs;

	CComboUI* m_cmbServer;
	CComboUI* m_cmbModality;
	CComboUI* m_cmbDate;
	CComboUI* m_cmbCond;
	CDateTimeUI* m_dtStart;
	CDateTimeUI* m_dtEnd;
	CEditUI* m_edtCondVal;
	CListUI* m_list;

	DbServer m_curdb;

	void ApplyConfig(const DbConfig& cfg);
	void ParseScript(DbConfig& cfg);
	void ReadScene();
	void SaveScene();

protected:
	void Notify(TNotifyUI& msg);
	void OnPrepare(TNotifyUI& msg);
	void OnExit(TNotifyUI& msg);

	void OnBtnSearch();
	int  ExcuteSQL(DbServer& dbcfg, const FindItem& cond);
	int  LoadImage(int idx);
	DString GetString(_variant_t& var);
};

